package com.ruoyi.caigou.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.caigou.domain.BuyOrderGoods;
import com.ruoyi.caigou.service.IBuyOrderGoodsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购订单商品Controller
 * 
 * @author lvql
 * @date 2024-11-02
 */
@RestController
@RequestMapping("/buyOrderGoods")
public class BuyOrderGoodsController extends BaseController
{
    @Autowired
    private IBuyOrderGoodsService buyOrderGoodsService;

    /**
     * 查询采购订单商品列表
     */
    @RequiresPermissions("caigou:buyOrderGoods:list")
    @GetMapping("/list")
    public TableDataInfo list(BuyOrderGoods buyOrderGoods)
    {
        startPage();
        List<BuyOrderGoods> list = buyOrderGoodsService.selectBuyOrderGoodsList(buyOrderGoods);
        return getDataTable(list);
    }

    @RequiresPermissions("caigou:buyOrderGoods:list")
    @GetMapping("/useList")
    public TableDataInfo useList(BuyOrderGoods buyOrderGoods)
    {
        startPage();
        List<BuyOrderGoods> list = buyOrderGoodsService.useSelectBuyOrderGoodsList(buyOrderGoods);
        return getDataTable(list);
    }

    /**
     * 导出采购订单商品列表
     */
    @RequiresPermissions("caigou:buyOrderGoods:export")
    @Log(title = "采购订单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyOrderGoods buyOrderGoods)
    {
        List<BuyOrderGoods> list = buyOrderGoodsService.selectBuyOrderGoodsList(buyOrderGoods);
        ExcelUtil<BuyOrderGoods> util = new ExcelUtil<BuyOrderGoods>(BuyOrderGoods.class);
        util.exportExcel(response, list, "采购订单商品数据");
    }

    /**
     * 获取采购订单商品详细信息
     */
    @RequiresPermissions("caigou:buyOrderGoods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(buyOrderGoodsService.selectBuyOrderGoodsById(id));
    }

    /**
     * 新增采购订单商品
     */
    @RequiresPermissions("caigou:buyOrderGoods:add")
    @Log(title = "采购订单商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyOrderGoods buyOrderGoods)
    {
        return toAjax(buyOrderGoodsService.insertBuyOrderGoods(buyOrderGoods));
    }

    /**
     * 修改采购订单商品
     */
    @RequiresPermissions("caigou:buyOrderGoods:edit")
    @Log(title = "采购订单商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyOrderGoods buyOrderGoods)
    {
        return toAjax(buyOrderGoodsService.updateBuyOrderGoods(buyOrderGoods));
    }

    /**
     * 删除采购订单商品
     */
    @RequiresPermissions("caigou:buyOrderGoods:remove")
    @Log(title = "采购订单商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(buyOrderGoodsService.deleteBuyOrderGoodsByIds(ids));
    }
}
